package homework;
//排序文件中数字
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;

public class work02 {
	public static void main(String[] args) throws IOException {
		FileInputStream isr=new FileInputStream("zy2.txt");
		FileOutputStream fos=new FileOutputStream("zy2sort.txt");
		int ch=0;
		ArrayList<Integer> list=new ArrayList<Integer>();

		while((ch=isr.read())!=-1){
			if(ch>=48&&ch<=57){
				list.add(ch);
			}
		}
		Integer [] arr=list.toArray(new Integer[list.size()]);
		isr.close();

		Arrays.sort(arr, new Comparator<Integer >() {
			@Override
			public int compare(Integer o1, Integer o2) {
				return o1-o2;
			}
		});
		System.out.println(Arrays.toString(arr));

		fos.write(Arrays.toString(arr).getBytes());
		fos.close();

	}

}
